const {DataTypes} = require("sequelize");

const seq = require("../db/seq");
const Record = require("./record.model");
const User = require("./user.model");
const Category = require("./category.model");
// 创建模型(Model zd_user -> 表 zd_users)
const Order = seq.define(
    "order",
    {
        // id 会被sequelize自动创建, 管理
        order_number: {
            type: DataTypes.STRING,
            allowNull: false,
            comment: "订单号",
        },
        cat_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            comment: "支持项目id",
        },
        user_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            comment: "资助人",
        },
        money: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false,
            comment: "资助金额",
        },
        status: {
            type: DataTypes.INTEGER,
            allowNull: false,
            comment: "订单状态, 0: 待支付, 1: 已支付, 2: 已取消",
            defaultValue: 0,
        }
    },
    {
        paranoid: true,
    }
);
Order.belongsTo(User, {
    foreignKey: "user_id",
    as: "user_info",
});
Order.belongsTo(Category, {
    foreignKey: "cat_id",
    as: "cat_info",
});
// 强制同步数据库(创建数据表)
// Order.sync({ force: true });

module.exports = Order;
